package com.lanxiao.cloud.modules.file.domain.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lanxiao.cloud.common.core.enums.StateEnum;
import com.lanxiao.cloud.common.mybatis.service.impl.BaseServiceImpl;
import com.lanxiao.cloud.modules.file.domain.model.FileConfigure;
import com.lanxiao.cloud.modules.file.domain.service.IFileConfigureService;
import com.lanxiao.cloud.modules.file.infrastructure.repository.FileConfigureMapper;
import java.util.Objects;
import org.springframework.stereotype.Service;

/**
 * @author ：qiaoliang
 * @date ：2021-10-25
 */
@Service
public class FileConfigureServiceImpl extends
    BaseServiceImpl<Long, FileConfigureMapper, FileConfigure> implements
    IFileConfigureService {

  @Override
  public void updateFileConfigure(FileConfigure fileConfigure) {
    if(Objects.nonNull(fileConfigure.getState()) &&
        StateEnum.NORMAL.equals(fileConfigure.getState())) {
      this.update(new FileConfigure(StateEnum.ERROR),
          new LambdaQueryWrapper<FileConfigure>()
              .ne(FileConfigure::getId, fileConfigure.getId()));
    }
    this.updateById(fileConfigure);
  }

}
